#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

/*
给定一个三角形，找出自顶向下的最小路径和，每一步只能移动到下一行中的相邻节点上
[
     [2],
   [3, 4],
  [6, 5, 7],
[4, 1, 8, 3]
]
最小路径和为11(2 + 3 + 5 + 1 = 11)
*/

void solution(vector<vector<int>> &triangle)
{
    int total = 0;
    for(auto vec: triangle){
        int min = vec[0];
        for(auto i: vec){
            if(min > i) min = i;
        }
        total += min;
    }
    cout << total << endl;
}

int main(int args, char *argv[])
{
    vector<vector<int>> triangle;
    triangle.push_back(vector<int>{2});
    triangle.push_back(vector<int>{3, 4});
    triangle.push_back(vector<int>{6, 5, 7});
    triangle.push_back(vector<int>{4, 1, 8, 3});

    solution(triangle);
    return 0;
}